<!doctype html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport"
          content="width=device-width, user-scalable=no, initial-scale=1.0, maximum-scale=1.0, minimum-scale=1.0">
    <meta http-equiv="X-UA-Compatible" content="ie=edge">
    <title>将字符串中 _ 后面的小写字母变大写，并且删除 _</title>
    <!--好的代码像粥一样,是得用时间和精力熬的。-->
</head>
<body>
<h3>
    输入'abc_bcd';  // 输出 'abcBcd'
    输入'a_3_c_d_ef';  // 输出 'a3CDEf'
    输入'_a_b_c_d_ef';  // 输出 '_aBCDEf'
</h3>
<script>
   function firstLTC(str) {
       var res;
       if (typeof str === 'string') {
           res = str.charAt(0).toUpperCase() + str.substr(1);
       } else {
           res = str;
       }
       return res;
   }
   function toCamelStyle(str) {
       var res;
       if (typeof str === 'string') {
           var isFisrstLUC = str.charAt(0) === '_';
           var wordArr;
           if(isFisrstLUC){
               str = str.substr(1);
           }
           wordArr = str.split('_');
           wordArr = wordArr.map(function (word, index) {
               // firstLetterToUpperCase 在题目 1 中实现
               return index === 0 ? word : firstLTC(word);
           });
           res = wordArr.join('');
           if(isFisrstLUC){
               res = '_' + res;
           }
       } else {
           res = str;
       }
       return res;
   }
    console.log(toCamelStyle('s_df_sd_f'));
</script>
</body>
</html>
